<?php

class Users2_PostReceiveApplicants_model extends CI_Model {

    public $table = "";
    //put your code here
    function __construct() {
        parent::__construct();
        $this->table = MYSQL_TABLE_PREFLIX.TABLE_USER2_RECEIVE_POST_APPLICANTS;
    }
  
    function Get($data){
        $query = $this->db->get_where($this->table, $data);
        return $query->result_array();
    }
    
    function Get_Advanced($select = '*', $where = array(), $group_by = array()){
        $query = $this->db->select($select)->group_by($group_by)->get_where($this->table, $where);
        return $query->result_array();
    }

    function Insert($data) {
        $this->db->insert($this->table, $data);
    }
    
    function Update($data, $where)  {
        $this->db->where($where);
        $this->db->update($this->table,$data);    
    }
    
    function Check($data){
        $query = $this->db->get_where($this->table,$data);
        if($query->num_rows){
            return true;
        }
        else{
            return false;
        }
    }
    function Get_Day_Receives($data){
        $PRAs = $this->Get_Advanced("*", $data, 'AcceptDate desc');
        $Array_Dates = array();
        $PRAsTemp = array();
        foreach($PRAs as $PRA){
            $PRA['AcceptDate'] = date("m/d/Y",strtotime($PRA['AcceptDate']));
            $PRAsTemp[] = $PRA;
            if(!in_array($PRA['AcceptDate'], $Array_Dates)){
                $Array_Dates[] = $PRA['AcceptDate'];
            }
        }
        
        $Result = array();
        $Result['Array_Dates']  = array();
        $Result['Array_Num']    = array();
        foreach($Array_Dates as $Array_Date){
            $i = 0;
            foreach($PRAsTemp as $PRA){
                if($PRA['AcceptDate'] == $Array_Date){
                    $i++;
                }
            }
            $Result['Array_Dates'][]    = $Array_Date;
            $Result['Array_Num'][]      =  $i;
        }
        return $Result;
    }
}
